package com.cy.sys.controller;

import com.cy.common.pojo.JsonResult;
import com.cy.sys.pojo.sysUserDeptPojo;
import com.cy.sys.service.UserServcie;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user/")
@ResponseBody
public class sysUserController {
    @Autowired
    private UserServcie user;

    @RequestMapping("doLogin")
    public JsonResult doLogin(String username, String password, boolean isRememberMe){
        System.out.println(username);
        Subject subject= SecurityUtils.getSubject();
        UsernamePasswordToken token=new UsernamePasswordToken(username,password);
        token.setRememberMe(isRememberMe);
        subject.login(token);

        return new JsonResult("dologIn o");
    }

    @RequestMapping("doFindPageObjects")
    public JsonResult doFindPageObjects(String username,Integer pageCurrent){

    return new JsonResult(user.doFindPageObjects(username,pageCurrent));
    }
    @RequestMapping("doValidById")
    public JsonResult doValidById(Integer id,Integer valid){
            user.validById(id,valid);
        return new JsonResult("okok");
    }
@RequestMapping("doSaveObject")
    public JsonResult doSaveObject(sysUserDeptPojo sysUserDeptPojo, Integer... roleIds){
        user.doSaveObject(sysUserDeptPojo,roleIds);
        return new JsonResult("heh ");
}
@RequestMapping("doFindObjectById")
    public JsonResult doFindObjectById(Integer id){

        return new JsonResult(user.doFindObjectById(id));
}
@RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(sysUserDeptPojo sysUserDeptPojo, Integer... roleIds){
            user.doUpdateObject(sysUserDeptPojo,roleIds);
        return new JsonResult("update ok!!!");

}
}
